package com.xuxu.blog.controller.elastic;

import com.xuxu.blog.service.elasticSearch.EsService;
import com.xuxu.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @className: ElasticSearchController
 * @author: Maxuxu
 * @date: 2022/8/24 23:54
 * @description: 通过es查询数据
 */
@RestController
@RequestMapping("/blog/elastic")
@Slf4j
public class ElasticSearchController {
    @Autowired
    EsService service;
    @GetMapping("/search/{name}/{current}")
    public R select(@PathVariable("name") String name,
                    @PathVariable("current") Integer current) throws IOException {
        List<Map<String, Object>> maps = service.highLightSearch(name, current, 5);
        // log.debug("查询的结果是：{}", maps);
        return R.ok().put("data", maps);
    }
    @GetMapping("/searchs/{name}")
    public R selectByName(@PathVariable("name") String name) throws IOException {
        List<Map<String, Object>> maps = service.highLightSearchNoPage(name);
        // log.debug("查询的结果是：{}", maps);
        return R.ok().put("data", maps);
    }
}
